﻿Shader "Unlit/Heart"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
	}
	SubShader
	{
		Tags { "RenderType"="Opaque" }
		LOD 100

		Pass
		{
			CGPROGRAM
			#pragma vertex vert
			#pragma fragment frag
			// make fog work
			#pragma multi_compile_fog
			
			#include "UnityCG.cginc"
			//#include "HLSL/ClassicNoise2D.hlsl"
			#include "HLSL/MyNoise.cginc"

			struct appdata
			{
				float4 vertex : POSITION;
				float2 uv : TEXCOORD0;
			};

			struct v2f
			{
				float2 uv : TEXCOORD0;
				float4 vertex : SV_POSITION;
			};

			sampler2D _MainTex;
			float4 _MainTex_ST;
			
			v2f vert (appdata v)
			{
				v2f o;
				o.vertex = UnityObjectToClipPos(v.vertex);
				o.uv = TRANSFORM_TEX(v.uv, _MainTex);
				return o;
			}
			float wnoise(float2 p) {
				float v = mnoise(p);
				return v;
			}

			float2 m = float2(0.8, 0.6);

			float fbm(float2 p){
				float f = 0.0;
				f += 0.5 * wnoise(p);
				p *= m * float2(2.02, 2.02);
				f += 0.25 * wnoise(p);

				p *= 2.03 * m;
				f += 0.125 * wnoise(p);

				p *= 2.01 * m;
				f += 0.0625 * wnoise(p);

				f /= 0.9375;
				return f;
			}

			fixed4 frag (v2f i) : SV_Target
			{
				// sample the texture
				//fixed4 col = tex2D(_MainTex, i.uv);
				float2 q = i.uv;
				float2 p = -1.0 + 2.0*q;
				//float2 p = q;
				float background = smoothstep(-0.25, 0.25, p.x);
				//fixed4 col = fixed4(0, 0, 0, 1);
				//float f = fbm(p*4);
				//float f = fbm(p*4);
				//float3 col1 = float3(f, f, f);
				p *= 2;
				p.x -= 0.75;

				float r = sqrt(dot(p, p));
				float a = atan2(p.y, p.x);
				float3 col1 = float3(1, 1, 1);

				float ss = 0.5 + 0.5 * sin(2.0 * _Time.y);
				float anim = 1.0 + 0.15 * ss * clamp(1.0-r, 0.0, 1.0);
				r *= anim;

				if(r < 0.8) {
					col1 = float3(0.0, 0.3, 0.4);
					float f = fbm(p*10);
					col1 = lerp(col1, float3(0.2, 0.5, 0.4), f);

					f = 1.0-smoothstep(0.2, 0.5, r);
					col1 = lerp(col1, float3(0.9, 0.6, 0.2), f);

					a += 0.1*fbm(15*p);

					f = smoothstep(0.1, 0.8 , fbm(float2(6*r, 30*a)));
					//f = fbm(float2(20*r, 25*a));
					col1 = lerp(col1, float3(1,1,1), f);

					f = smoothstep(0.1, 0.8, fbm(float2(10*r, 15*a)));
					col1 *= 1.0 - f;

					f = smoothstep(0.5, 0.8, r);
					col1 *= 1.0 - 0.5*f;

					f = smoothstep(0.2, 0.25, r);
					col1 *= f;

					f = 1.0 - smoothstep(0.0, 0.5, length(p-float2(0.24, 0.2)));
					col1 += float3(1.0, 0.9, 0.8) * f * 0.5;

					f = smoothstep(0.7, 0.8, r);
					col1 = lerp(col1, float3(1, 1, 1), f);

				}

				float4 col = float4(col1 * background, 1);
				return col;
			}
			ENDCG
		}
	}
}
